package logger;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class OurLogger {
	public Logger logger;

	/**
	 * OurLogger creates a logger for program with requested formatting
	 * @param logFilename log filename
	 */
	public OurLogger(String logFilename) {
		this.logger = Logger.getLogger("serverLogger");
		Handler fh= null;
		try{ fh = new FileHandler(logFilename);
		}catch(IOException e){System.err.println(e.getMessage());}

		//set format for logger
	    OurFormatter f = new OurFormatter();
	    fh.setFormatter(f);

	    this.logger.addHandler(fh);
	    Handler[] handlers = Logger.getLogger( "" ).getHandlers();
	      for ( int index = 0; index < handlers.length; index++ ) {
	        handlers[index].setLevel( Level.OFF);
	        handlers[index].setFormatter(f);
	      }
	    fh.setLevel(Level.INFO);
	    this.logger.setLevel(Level.INFO);
	}
}
